package org.artifact.builder.extend;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import cn.hutool.core.util.StrUtil;

/**
 * @author : DengYing
 * @CreateDate : 2017年11月1日 下午2:34:28
 * @Description ：设计器扩展
 * 
 */
public abstract class AbstractDesignExtend {
	
	/** 注释 */
	public String remarks;
	
	
	public String getRemarks() {
		return remarks;
	}


	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}


	/**
	 * 解码扩展
	 * 
	 * @param comtent
	 * @return
	 */
	public Map<String, String> decoder(String comtent) {
		Map<String, String> spreadMap = new HashMap<String, String>();
		comtent = comtent.trim();
		List<String> spreads = StrUtil.split(comtent, StrUtil.C_LF, true, true);
		final char C_EQ = '=';
		for (String spread : spreads) {
			List<String> spread_unit = StrUtil.split(spread, C_EQ, true, true);
			if (spread_unit.size() != 2) {
				continue;
			}
			String key = spread_unit.get(0);
			String val = spread_unit.get(1);
			spreadMap.put(key, val);
		}
		return spreadMap;
	}
	
	
	/**
	 * 编码码
	 * 
	 * @param map
	 * @return
	 */
	public String encoder(Map<String, String> map) {
		StringBuffer sb = new StringBuffer();
		int i = 0; 
		final char C_EQ = '=';
		for (Entry<String, String> e : map.entrySet()) {
			if (!"remarks".equals(e.getKey())) {
				continue;
			}
			if (i > 0) {
				sb.append("\\n");
			}
			sb.append(e.getKey()).append(C_EQ).append(e.getValue());
			i++;
		}
		return sb.toString();
	}
}
